package com.hemaapp.yjnh.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hemaapp.yjnh.view.BaseButtonDialog;
import com.hemaapp.yjnh.view.BaseButtonDialog.OnButtonListener;
import com.hemaapp.hm_FrameWork.HemaNetTask;
import com.hemaapp.hm_FrameWork.result.HemaBaseResult;
import com.hemaapp.yjnh.BaseActivity;
import com.hemaapp.yjnh.BaseHttpInformation;
import com.hemaapp.yjnh.BaseUtil;
import com.hemaapp.yjnh.R;

public class FeedbackActivity extends BaseActivity implements OnClickListener {

	private ImageButton left;
	private TextView title;
	private TextView right;

	private EditText edit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		setContentView(R.layout.activity_feedback);
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.title_left_btn:
			finish();
			break;
		case R.id.title_right_btn:
			String content=edit.getText().toString().trim();
			if(isNull(content)){
				BaseButtonDialog dialog=new BaseButtonDialog(mContext);
				dialog.setText("反馈意见不能为空");
				dialog.setRightButtonText("确定");
				dialog.setButtonListener(new OnButtonListener() {
					
					@Override
					public void onRightButtonClick(BaseButtonDialog dialog) {
						// TODO Auto-generated method stub
						dialog.cancel();
					}
					
					@Override
					public void onLeftButtonClick(BaseButtonDialog dialog) {
						// TODO Auto-generated method stub
						
					}
				});
				break;
			}
			getNetWorker().adviceAdd(getApplicationContext().getUser().getToken(), content);
			break;
		default:
			break;
		}
	}

	@Override
	protected void callBeforeDataBack(HemaNetTask netTask) {
		// TODO Auto-generated method stub

		BaseHttpInformation info=(BaseHttpInformation) netTask.getHttpInformation();
		switch (info) {
		case ADVICE_ADD:
			showProgressDialog("正在提交");
			break;
		default:
			break;
		}
	}

	@Override
	protected void callAfterDataBack(HemaNetTask netTask) {
		// TODO Auto-generated method stub

		BaseHttpInformation info=(BaseHttpInformation) netTask.getHttpInformation();
		switch (info) {
		case ADVICE_ADD:
			cancelProgressDialog();
			break;

		default:
			break;
		}
	}

	@Override
	protected void callBackForServerSuccess(HemaNetTask netTask,
			HemaBaseResult baseResult) {
		// TODO Auto-generated method stub

		BaseHttpInformation info=(BaseHttpInformation) netTask.getHttpInformation();
		switch (info) {
		case ADVICE_ADD:
			showTextDialog("意见提交成功");
			new Handler().postDelayed(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					finish();
				}
			}, 500);
			break;

		default:
			break;
		}
	}

	@Override
	protected void callBackForServerFailed(HemaNetTask netTask,
			HemaBaseResult baseResult) {
		// TODO Auto-generated method stub

		BaseHttpInformation info=(BaseHttpInformation) netTask.getHttpInformation();
		switch (info) {
		case ADVICE_ADD:
			showTextDialog(baseResult.getMsg());
			break;

		default:
			break;
		}
	}

	@Override
	protected void callBackForGetDataFailed(HemaNetTask netTask, int failedType) {
		// TODO Auto-generated method stub

		BaseHttpInformation info=(BaseHttpInformation) netTask.getHttpInformation();
		switch (info) {
		case ADVICE_ADD:
			showTextDialog("意见提交失败");
			break;

		default:
			break;
		}
	}

	@Override
	protected void findView() {
		// TODO Auto-generated method stub
		left = (ImageButton) findViewById(R.id.title_left_btn);
		title = (TextView) findViewById(R.id.title_text);
		right = (TextView) findViewById(R.id.title_right_btn);
		edit = (EditText) findViewById(R.id.edit);
	}

	@Override
	protected void getExras() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void setListener() {
		// TODO Auto-generated method stub
		title.setText("意见反馈");
		left.setOnClickListener(this);
		right.setText("提交");
		right.setVisibility(View.VISIBLE);
		right.setOnClickListener(this);
	}

}
